<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
mm_showMyFileName( __FILE__ );



$user_id = @JRequest::getInt("user_id");
$q = "SELECT o.order_id, o.order_total FROM #__vm_orders o INNER JOIN #__vm_user_info u ON u.user_info_id = o.user_info_id WHERE o.user_id = $user_id ";
//var_dump($q);
$db =& JFactory::getDBO();
$db->setQuery($q);
$result = $db->loadObjectList();

echo "We're redirecting you to QuickPay, please wait! ...";

$protocol = '3';
$msgtype = 'authorize';
$merchant = '28655592';
$language = 'da';
$ordernumber = "0000".$result["0"]->order_id;
//$ordernumber = time();
$amount = ((float)$result["0"]->order_total)*100;

//$ordernumber = "0000".time();
//$amount = (float)@JRequest::getVar("total",0);

$currency = 'DKK';
$continueurl = JURI::base().'index.php?option=com_virtuemart&page=checkout.thankyou';
$cancelurl = 'http://www.vnexpress.net';
$callbackurl = JURI::base().'index.php?option=com_virtuemart&page=checkout.qpcallback';
                
$autocapture = '0';
$cardtypelock = '';
$description = 'description';
$testmode = 1;
$splitpayment = 0;
$md5word = '22x49Rfb4t15sYp8B94Ml6EFNVeGAZdHPg2qkm7Czu6L1395Uh89Qa27vy67n65I';
$md5check = md5($protocol . $msgtype . $merchant . $language . $ordernumber . $amount . $currency . $continueurl . $cancelurl . $callbackurl . $autocapture . $cardtypelock . $description . $testmode. $splitpayment . $md5word);

?>
<script type="text/javascript">
    $(document).ready(function(){
      $("#leasingForm").submit();
    });
</script>
<form id="leasingForm" action="https://secure.quickpay.dk/form/" method="post">
    <input type="hidden" name="protocol" value="<?php echo $protocol ?>" />
    <input type="hidden" name="msgtype" value="<?php echo $msgtype ?>" />
    <input type="hidden" name="merchant" value="<?php echo $merchant ?>" />
    <input type="hidden" name="language" value="<?php echo $language ?>" />
    <input type="hidden" name="ordernumber" value="<?php echo $ordernumber ?>" />
    <input type="hidden" name="amount" value="<?php echo $amount ?>" />
    <input type="hidden" name="currency" value="<?php echo $currency ?>" />
    <input type="hidden" name="continueurl" value="<?php echo $continueurl ?>" />
    <input type="hidden" name="cancelurl" value="<?php echo $cancelurl ?>" />
    <input type="hidden" name="callbackurl" value="<?php echo $callbackurl ?>" />
    <input type="hidden" name="autocapture" value="<?php echo $autocapture ?>" />
    <input type="hidden" name="cardtypelock" value="<?php echo $cardtypelock ?>" />
    <input type="hidden" name="md5check" value="<?php echo $md5check ?>" />
	<input type="hidden" name="description" value="<?php echo $description ?>" />
	<input type="hidden" name="testmode" value="<?php echo $testmode ?>" />
	<input type="hidden" name="splitpayment" value="<?php echo $splitpayment ?>" />
	<input type="hidden" name="secret" value="<?php echo $md5word ?>" />
    <!--<input type="submit" value="Open Quickpay payment window" />-->
</form>